| ++ (Increment) The Increment operator is used to increment the numeric value of a variable by a factor of one. There are two ways of assigning this operator, the first being the pre-increment method (++ variableName). The numeric contents of the variable are incremented, with this incremented value being returned as the result. The second method, post-increment (variableName ++), increments the numeric value of the variable by one, but returns the original value in the variable before being incremented. In both methods, if the value of the variable is anything other than a Number data type, an attempt is made to convert it to a number. syntax: ++ variableName variableName ++ EXAMPLE var variableOne = new String("500"); newValue = ++ variableOne; document.write("The result in newValue is " + newValue); newValue2 = variableOne ++; document.write("The new result in newValue2 is " + newValue2); document.write("The end result in variableOne is " + variableOne); This example shows both the pre and post incremental methods. The value in variableOne is first converted to a Number data type, then pre-incremented to a value of 501, which is held in the variable newValue. The value in variableOne is then post-incremented to return a value of 501, which is held in the variable newValue2. The end result, which is 502, is now held in the variableOne variable. |